/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */

package com.hexidec.ekit.component;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import wl.util.Utils;
import wl.ui.ButtonLabel;
import wl.ui.SimpleColorChooser;

/**
 *
 * @author Williams Lopez
 */
public class ColorPickerButtom extends ButtonLabel{

    SimpleColorChooser scch;
    Action action;
    boolean changeForegraundColor;

    public ColorPickerButtom(Action _action) {
        super();
        this.action = _action;
        scch = new SimpleColorChooser();
        this.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                scch.showInPopup(ColorPickerButtom.this, 0, ColorPickerButtom.this.getHeight());
            }
        });

        scch.setChoseColorListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ActionEvent event = new ActionEvent(e.getSource(), e.getID(), Utils.colorToHex((Color)e.getSource()));
                action.actionPerformed(event);
                if(changeForegraundColor){
                    ColorPickerButtom.this.setForeground((Color)e.getSource());
                }

            }
        });
        this.setFocusable(false);
    }

    public boolean isChangeForegraundColor() {
        return changeForegraundColor;
    }

    public void setChangeForegraundColor(boolean changeForegraundColor) {
        this.changeForegraundColor = changeForegraundColor;
    }






}
